<?php

namespace app\common\model;

use think\Cache;
use think\Model;

/**
 * 地区数据模型
 */
class AddressArea extends Model
{

    // 表名,不含前缀
    protected $name = 'address_area';
    // 追加属性
    protected $append = [
    ];

    public function childs()
    {
        return $this->hasMany(AddressArea::class, 'pid', 'value')->field('id as value, name as label, pid, level');
    }

    public static function getAreaList()
    {
        return self::where('level',1)->with('childs.childs')->field('id as value, name as label, pid, level')->order('value asc')->select();
    }


}
